$(function () {
    let num = 1;
    const row = 10;
    let danum;
    pagetion(num)

    function pagetion(num) {
        $('.xiao').html(num);
   
        $.ajax({
            url: 'http://139.9.177.51:3333/p2p/getBorrowList',
            type: 'get',
            data: {
                pageIndex: num,
                pageSize: row
            },
            dataType: 'json',
            success: function (res) {
                //console.log(res);
                //console.log(res.data);
                let leng = res.data.length;
                let data = res.data;
                let trS = '';
                for (let i = 0; i < leng; i++) {
                    /*  if(data[i].repaytype==0){
                         data[i].repaytype='按月分期'
                     }else{
                         data[i].repaytype='按月到期' 
                     } */
                    data[i].repaytype = data[i].repaytype == 0 ? data[i].repaytype = '按月分期' : data[i].repaytype = '按月到期'
                    //console.log(data[i]);
                    trS += `
                <tr>
                    <td>${data[i].username}</td>
                    <td>${data[i].title}</td>
                    <td>${data[i].interest}%</td>
                    <td>${data[i].borrowmoney}</td>
                    <td>${data[i].repaytype}</td>
                    <td>${data[i].ownmoney}</td>
                    <td><button id="btn" data-id="${data[i].id}">查看</button></td>
                 </tr>
                    `
                }
                $('#list').html(trS)
            }
        })
    }


    $('#list').on('click', 'button', function () {
        let borrowid = $(this).data('id')
        // console.log(borrowid);
        localStorage.setItem('borrowid', borrowid)
        location.href = '#personage/borrowInfo'
    })

   
    $('#up').click(function () {
        num--;
        if (num < 1) {
            num = 1;
        }
       // $('.xiao').text(num)
       pagetion(num) 
    })
    $('#next').click(function () {
        num++;
        if (num > danum) {
            num = danum
        }
        //$('.xiao').text(num)
        pagetion(num)
    })
})